<template>
  <div style="padding: 20px">
    <right-toolbar @queryTable="get_list"></right-toolbar>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="id" label="id" width="120"> </el-table-column>
      <el-table-column prop="goodsId" label="goodsid" width="120">
      </el-table-column>
      <el-table-column prop="userId" label="用户" width="200">
      </el-table-column>
      <el-table-column prop="goods.title" label="盒子名称" width="200">
      </el-table-column>
      <el-table-column prop="goods.imgurl" label="封面" width="200">
        <template slot-scope="scope">
          <img
            :src="scope.row.goods.imgurl"
            style="width: 100px; height: 100px"
          />
        </template>
      </el-table-column>
      <el-table-column
        prop="goods.price"
        label="价格"
        width="120"
      ></el-table-column>
      <el-table-column prop="status" label="状态" width="120">
        <template slot-scope="scope">
          <el-tag :type="['', 'success', 'info', 'danger'][scope.row.status]">{{
            ["", "已通过", "待审核", "未通过"][scope.row.status]
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="日期"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="updataRow(scope.row)"
            type="text"
            size="small"
          >
            修改状态
          </el-button>
          <el-button
            @click.native.prevent="look(scope.row)"
            type="text"
            size="small"
          >
            查看详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="page.pageSize"
      :total="total"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>

    <!-- 弹出窗 -->
    <el-dialog
      title="修改状态"
      :visible.sync="dialogVisible"
      width="30%"
      :beforeClose="handleClose"
    >
      <el-form :model="form" label-width="80px" ref="form">
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio :label="1">通过</el-radio>

            <el-radio :label="3">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="意见" prop="message">
          <el-input v-model="form.message" type="textarea" rows="3"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="genggai">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { get_list, update_status } from "@/api/czz/index.js";
export default {
  name:'Czz/dai_list',
  data() {
    return {
      tableData: [],
      page: {
        page: 1,
        pageSize: 10,
      },
      loading: false,
      total: 0,
      search: {
        status: 2,
        id: null,
        message: null,
      },
      form: {
        status: 1,
      },
      dialogVisible: false,
    };
  },
  methods: {
    updataRow(row) {
      this.dialogVisible = true;
      this.form.id = row.id;
      // update_status({
      //   id: row.id,
      //   status: row.status == 1 ? 2 : 1,
      // }).then((res) => {
      //   this.get_list();
      // });
    },
    genggai() {
      update_status(this.form).then((res) => {
        //消息通知
        if (res.code == 200) {
          this.$message({
            message: "修改成功",
            type: "success",
          });
        }
        this.dialogVisible = false;
        this.get_list();
      });
    },
    get_list() {
      this.loading = true;

      get_list({
        page: this.page.page,
        pageSize: this.page.pageSize,
        ...this.search,
      }).then((res) => {
        this.loading = false;
        this.tableData = res.data.list;
        this.total = res.data.total;
      });
    },
    handleSizeChange(val) {
      this.page.limit = val;
      this.get_list();
    },
    handleCurrentChange(val) {
      this.page.page = val;
      this.get_list();
    },
    handleSearch() {
      this.page.page = 1;
      this.get_list();
    },
    handleReset() {
      this.search = {
        status: 0,
      };
      this.get_list();
    },

    //查看详情
    look(row) {
      const tableId = row.goodsId;
      const tableName = row.title;
      //   const params = { pageNum: this.queryParams.pageNum };
      console.log(row);

      this.$tab.openPage(
        "查看待审核[" + tableName + "]盒子商品详情",
        "/czz/goods_xq/index/" + tableId
      );
    },
  },
  mounted() {
    this.get_list();
  },
};
</script>

<style></style>
